package com.joysuch.wwyt.bp.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.joysuch.wwyt.core.support.AutoSetCommonFieldListener;
import lombok.Data;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

import static javax.persistence.GenerationType.IDENTITY;


@EntityListeners({AuditingEntityListener.class, AutoSetCommonFieldListener.class})
@Entity
@Table(name = "wwyt_bp_work_safety_cert_file_analyze")
@SQLDelete(sql = "update wwyt_bp_work_safety_cert_file_analyze set DELETE_FLAG = '1' where id= ?")
@SQLDeleteAll(sql = "update wwyt_bp_work_safety_cert_file_analyze set DELETE_FLAG = '1' where id= ?")
@Where(clause = "DELETE_FLAG = '0'")
@Data
public class BpWorkSafetyFileAnalyze implements Serializable {

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    private Long id;

    //作业证id
    @Column(name = "cert_id")
    private Long certId;

    //作业证类型
    @Column(name = "type")
    private String type;

    //分析时间
    @Column(name = "date")
    private Date date;

    //分析点名称
    @Column(name = "point_name")
    private String pointName;

    //分析数据
    @Column(name = "data")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private String data;

    //分析人id
    @Column(name = "user_id")
    private Long userId;

    //设计的其他作业
    @Column(name = "other_cert")
    private Long otherCert;

    //签名id
    @Column(name = "signer_id")
    private Long signerId;

    //分析人类型:IN公司人员;OUT承包商
    @Column(name = "user_type")
    private Integer userType;

    @org.springframework.data.annotation.CreatedBy
    @Column(name = "create_by")
    private Long createBy;

    @org.springframework.data.annotation.CreatedDate
    @Column(name = "create_time")
    private Date createTime;

    @org.springframework.data.annotation.LastModifiedBy
    @Column(name = "update_by")
    private Long updateBy;

    @org.springframework.data.annotation.LastModifiedDate
    @Column(name = "update_time")
    private Date updateTime;

    @Column(name = "deleteFlag")
    private String deleteFlag;

    @Column(name = "orgCode")
    private String orgCode;

    @Column(name = "tenentId")
    private Long tenentId;

    public int hashCode() {
        return new HashCodeBuilder().append(getId()).toHashCode();
    }

    public boolean equals(Object obj) {
        if (obj instanceof BpWorkSafetyFileAnalyze == false)
            return false;
        if (this == obj)
            return true;
        BpWorkSafetyFileAnalyze other = (BpWorkSafetyFileAnalyze) obj;
        return new EqualsBuilder().append(getId(), other.getId()).isEquals();
    }
}
